﻿using System;
using System.Net;
using System.Text;
namespace AllInfoC
{
    class HttpClient
    {
        public String HttpGet(string s)
        {
            // used to build entire input
            var sb = new StringBuilder();
            // used on each read operation
            var buf = new byte[8192];
            // prepare the web page we will be asking for
            var request = (HttpWebRequest)
                WebRequest.Create(s);
            // execute the request
            var response = (HttpWebResponse)
                request.GetResponse();
            // we will read data via the response stream
            var resStream = response.GetResponseStream();
            int count;
            if (resStream == null)
            {
                return String.Empty;
            }
            do
            {
                // fill the buffer with data
                count = resStream.Read(buf, 0, buf.Length);
                // make sure we read some data
                if (count == 0) break;
                // translate from bytes to ASCII text
                string tempString = Encoding.ASCII.GetString(buf, 0, count);
                // continue building the string
                sb.Append(tempString);
            }
            while (count > 0); // any more data to read?
            // print out page source
            Console.WriteLine(sb.ToString());
            return sb.ToString();
        }
    }
}
